<?php 
    $url = new Url();
    $link_url = Yii::app()->params['urlRs']."/upload/upload_library.php?forder_up=exercise";  
?>
<link type="text/css" href="<?=Yii::app()->params["urlRs"] ?>/js/jqueryui/jquery-ui-1.8.23.custom.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Yii::app()->params["urlRs"] ?>/js/jqueryui/jquery-ui-1.8.23.custom.min.js"></script>

<link href="<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/css/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/js/handlers.js"></script>

<div id="main">
    <?php $this->widget("SideBar");?>

    <div id="content">
        <div class="flash notice" id="flash_notice" style="display: none;">Cập nhật tài khoản thành công.</div>
        <div id="errorExplanation" style="display: none;">
            <ul id="err_msg">
                <!--<li>Email không thể để trắng</li>-->
            </ul>
        </div>
        <div class="contextual">
            <a href="<?php echo $url->createUrl("user/changepass"); ?>" class="icon icon-passwd">Đổi mật khẩu</a>

        </div>

        <h2>Cá nhân</h2>

        <div class="splitcontentleft">
            <fieldset class="box tabular">
                <legend>Thông tin</legend>
                <p>
                    <label for="user_firstname">Họ tên<span class="required"> *</span></label>
                    <input id="fullname" name="fullname" size="30" value="<?php echo $data['fullname']; ?>" type="text">
                </p>
                <p>
                    <label for="user_lastname">Ngày sinh</label>
                    <input id="birthday" name="birthday" size="30" value="<?php if($data['birthday'] != ''){echo date("d/m/Y",$data['birthday']);} ?>" type="text">
                </p>
                <p>
                    <label for="user_mail">Email<span class="required"> *</span></label>
                    <input id="email" name="email" size="30" value="<?php echo $data['email']; ?>" type="text">
                </p>
                <p>
                    <label for="user_mail">Số điện thoại</label>
                    <input id="mobile" name="mobile" size="30" value="<?php echo $data['mobile']; ?>" type="text">
                </p>
                <p>
                    <label for="user_mail">Địa chỉ</label>
                    <input id="address" name="address" size="30" value="<?php echo $data['address']; ?>" type="text">
                </p>
                <p>
                    <label for="user_mail">Chứng minh thư</label>
                    <input id="personal_id" name="personal_id" size="30" value="<?php echo $data['personal_id']; ?>" type="text">
                </p>                
                <p><label for="user_mail">Ảnh đại diện</label>                
                    <input type="text" id="txtFileName" disabled="disabled" style="background-color: #FFFFFF;" size="30" value="<?php echo $data['image']; ?>" />                            
                    <span id="spanButtonPlaceholder"></span>                                            
                </p>
                <div id="divFileProgressContainer" style="margin-left:175px;"></div>
            </fieldset>



            <input name="commit" value="Lưu" type="button" onclick="update_info(<?php echo $data['user_id']; ?>)">
        </div>        

        <div class="splitcontentright" id="thumbnails" style="margin-top:8px;">
            <img style="max-width: 300px;max-height: 300px;" src="<?=Yii::app()->params["urlImage"].$data['image']; ?>" />
        </div>

        <div style="clear:both;"></div>
    </div>
</div>
 
<script type="">

    //-----------------------------------------------------------------------------------------------------------------//   

    var filename = "";
    var filepath = "";
    function getdata(data_json){              
        var json = $.parseJSON(data_json);
        var code = json.code;   

        if(code == '105')
            {
            filename = json.data["filename"];            
            //filetype = json.data["filetype"];
            //filesize = json.data["filesize"];
            filepath = "/" + json.data["forder_up"]  + "/" + ""+filename;
            path = "<?=Yii::app()->params['urlImage']?>/"+ json.data["forder_up"]  + "/" + ""+filename;            
            //path = "http://images.az24.vn"+ json.data["path"]  + "/" + ""+filename;            
            $("#txtFileName").val(filepath);
            $("#thumbnails").html("<img style='max-height: 300px;max-width: 300px;' src='"+path+"'/>");                          
        }
        else
            {
            var msg = json.msg;                
            alert(msg);    
        }
    }

    //-----------------------------------------------------------------------------------------------------------------//

    var swfu;
    window.onload = function () {
        swfu = new SWFUpload({
            // Backend Settings
            upload_url: "<?=$link_url ?>",
            post_params: "resume_file",

            // File Upload Settings
            file_size_limit : "4 MB",
            file_types : "*.*",
            file_types_description : "Tài liệu",
            file_upload_limit : "0",

            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,

            // Button Settings
            button_image_url : "<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/XPButtonUploadText_61x22.png",
            button_placeholder_id : "spanButtonPlaceholder",
            button_width: 61,
            button_height: 22,

            // Flash Settings
            flash_url : "<?php echo Yii::app()->params['urlRs']; ?>/js/swfupload/swfupload.swf",

            custom_settings : {
                upload_target : "divFileProgressContainer"
            },

            // Debug Settings
            //debug: true
        });
    };

    //-----------------------------------------------------------------------------------------------------------------//    

    $(function() {
        $('#birthday').datepicker({
            changeYear: true,
            dateFormat:'dd/mm/yy',                                    
            showOn:'both',           
            buttonImage: '<?=Yii::app()->params["urlRs"]."/images/calendar.png"?>',
            buttonImageOnly: 'true'
        });   

        $(".ui-datepicker-trigger").css("margin-bottom","-5px");
        $(".ui-datepicker-trigger").css("margin-left","5px"); 
    });

    function update_info(user_id){
        var fullname = $('#fullname').val();       
        var birthday = $('#birthday').val();       
        var email = $('#email').val();    
        var mobile = $('#mobile').val();    
        var address = $('#address').val();    
        var personal_id = $('#personal_id').val();            
        var image = $('#txtFileName').val();            
        var flag_err = 0;
        $('#errorExplanation').slideUp('slow');
        $('#err_msg').empty();        
        if(fullname == ''){
            flag_err = 1;
            err_msg = '<li>Chưa điền tên!</li>'
            $('#err_msg').append(err_msg);
        }        
        if(email == ''){
            flag_err = 1;
            err_msg = '<li>Chưa điền mail!</li>'
            $('#err_msg').append(err_msg);
        }

        if(flag_err == 1){
            $('#errorExplanation').slideDown('slow');
            return false;    
        }else{            
            $('#errorExplanation').slideUp('slow');
            var strUrl = '<?=$url->createUrl("user/ajaxSubmitUpdate") ?>';            
            loadingAjax();
            $.ajax({
                type: "GET",
                url: strUrl,
                data: {user_id:user_id,fullname:fullname,birthday:birthday,email:email,mobile:mobile,address:address,personal_id:personal_id,image:image},
                success: function(msg){                            
                    if(msg==1){                       
                        $('#errorExplanation').slideUp('slow');
                        $('#flash_notice').slideDown('slow');
                    }else if(msg==-1){
                        err_msg = '<li>Có lỗi!</li>'
                        $('#err_msg').append(err_msg);   
                        $('#errorExplanation').slideDown('slow');                     
                    }

                }
            });
        }  
        closeLoadingAjax();
    }

    function delete_user(user_id){
        if(confirm("Bạn có chắc chắn muốn xóa tài khoản?")){
            var strUrl = '<?=$url->createUrl("user/submitLogin") ?>';            
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {user_id:user_id},
                success: function(msg){                
                    if(msg==1){
                        alert('Đăng nhập thành công!');
                        location.reload();
                    }else if(msg==0){
                        alert('Tài khoản hoặc mật khẩu không chính xác!');                    
                    }
                    $("#login_button").removeAttr("disabled");

                }                
            });
        }
    }

</script>